package com.iqiyi.pps.epg.core.model.channel;

import com.alibaba.fastjson.JSONArray;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by karkarrotxu on 2015/11/12.
 */
@Entity
@Table(name = "channel_search_settings")
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONE)
public class SearchSettingConfig {
    public static final int USE_LIMIT = 1;
    public static final int USE_ZERO = 0;
    public static final int NO_LIMIT = -1;
    private long id;
    private int checkCopyRightType = NO_LIMIT;
    private int checkBossType = USE_ZERO;
    private int checkPublishType = USE_LIMIT;
    private String regionLimit;
    private String onlineLimit;

    private List<Integer> needRegions;
    private List<Integer> needOnlines;

    private String opUser;
    private Timestamp addTime;
    private Timestamp updateTime;

    @Id
    @Column(name = "id")
    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    @Transient
    public List<Integer> getNeedRegions() {
        return needRegions;
    }

    @Transient
    public List<Integer> getNeedOnlines() {
        return needOnlines;
    }

    @Column(name = "check_copyright_type")
    public int getCheckCopyRightType() {
        return checkCopyRightType;
    }

    public void setCheckCopyRightType(int checkCopyRightType) {
        this.checkCopyRightType = checkCopyRightType;
    }

    @Column(name = "check_boss_type")
    public int getCheckBossType() {
        return checkBossType;
    }

    public void setCheckBossType(int checkBossType) {
        this.checkBossType = checkBossType;
    }

    @Column(name = "check_publish_type")
    public int getCheckPublishType() {
        return checkPublishType;
    }

    public void setCheckPublishType(int checkPublishType) {
        this.checkPublishType = checkPublishType;
    }

    @Column(name = "op_user")
    public String getOpUser() {
        return opUser;
    }

    public void setOpUser(String opUser) {
        this.opUser = opUser;
    }

    @Column(name = "add_time")
    public Timestamp getAddTime() {
        return addTime;
    }

    public void setAddTime(Timestamp addTime) {
        this.addTime = addTime;
    }

    @Column(name = "update_time", insertable = false, updatable = false)
    public Timestamp getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Timestamp updateTime) {
        this.updateTime = updateTime;
    }

    @Column(name = "region_limit")
    public String getRegionLimit() {
        return regionLimit;
    }

    public void setRegionLimit(String regionLimit) {

        this.regionLimit = regionLimit;
    }

    @Column(name = "online_limit")
    public String getOnlineLimit() {
        return onlineLimit;
    }

    public void setOnlineLimit(String onlineLimit) {

        this.onlineLimit = onlineLimit;
    }

    public void appendRegionLimitClient(Integer key) {
        if (needRegions == null) {
            needRegions = new ArrayList<Integer>();
        }
        if (!needRegions.contains(key)) {
            needRegions.add(key);
        }

    }

    public void appendOnlineLimitClient(Integer key) {
        if (needOnlines == null) {
            needOnlines = new ArrayList<Integer>();
        }
        if (!needOnlines.contains(key)) {
            needOnlines.add(key);
        }
    }

    public void recordLimit(){
        onlineLimit = needOnlines.toString();
        regionLimit = needRegions.toString();
    }
    public void readLimit(){
        if (onlineLimit != null && !onlineLimit.isEmpty()) {
            needOnlines = JSONArray.parseArray(onlineLimit, Integer.class);
        } else {
            needOnlines = new ArrayList<Integer>();
        }
        if (regionLimit != null && !regionLimit.isEmpty()) {
            needRegions = JSONArray.parseArray(regionLimit, Integer.class);
        } else {
            needRegions = new ArrayList<Integer>();
        }
    }

    public void setNeedRegions(List<Integer> needRegions) {
        this.needRegions = needRegions;
    }

    public void setNeedOnlines(List<Integer> needOnlines) {
        this.needOnlines = needOnlines;
    }


}

